function load(id, url) {
	$('#'+id).load(url);
}

function setCurrent(id) {
	$('.current').removeClass('current');
	$('#'+id).addClass('current');
}

function loadPage(url) {
	load('main', url);
}

function setLinkHelper(id1, id2, url) {
	$('#'+id1).click( function() {loadPage(url); setCurrent(id2);});
}

function setLink(id, url) {
	setLinkHelper(id, id, url);
}

function setHeaderLinks() {
	setLinkHelper('logoLink', 'homeLink', 'shared/welcome.html');
	setLink('homeLink', 'shared/welcome.html');
	setLink('aboutUsLink', 'public/about.html');
	setLink('editAccountLink', 'shared/editUserAccount.jsp');
	setLink('courseSearchLink', 'shared/searchCourse.jsp');
	setLink('allCoursesLink', 'shared/allCourses.jsp');
	setLink('allUsersLink', 'shared/allUsers.jsp');
}

function setStudentLinks() {
	setLink('timetableLink', 'student/timetable.jsp?num=1');
	setLink('myCoursesLink', 'student/myCourses.jsp');
	setLink('availableCoursesLink', 'student/availableCourses.jsp');
}

function setAdminLinks() {
	setLink('newCourseLink', 'admin/newCourse.jsp');
}

function setLoggedOutHeaderLinks() {
	setLinkHelper('logoLink', 'homeLink', 'public/login.html');
	setLink('homeLink', 'public/login.html');
	setLink('registerLink', 'public/register.jsp');
	setLink('aboutUsLink', 'public/about.html');
}

function postToServlet(formId, url, successFunc) {
	if(typeof(successFunc) == "undefined")
		$.post(url, $('#'+formId).serialize());
	else
		$.post(url, $('#'+formId).serialize()).complete(successFunc);
}

function setPostFormToServlet(formId, url) {
	$('#'+formId).submit(function(event) {event.preventDefault(); postToServlet(formId, url);});
}

function setCheckAndPostFormToServlet(formId, url, checkFunc) {
	$('#'+formId).submit(function(event) {event.preventDefault(); if (!checkFunc()) return false; postToServlet(formId, url);});
}

function setPostFormToServletWithCompleteFunc(formId, url, successFunc) {
	$('#'+formId).submit(function(event) {event.preventDefault(); postToServlet(formId, url, successFunc);});
}

function setCheckAndPostFormToServletWithCompleteFunc(formId, url, checkFunc, successFunc) {
	$('#'+formId).submit(function(event) {event.preventDefault(); if (!checkFunc()) return false; postToServlet(formId, url, successFunc);});
}
